import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Version,
  Inject,
} from '@nestjs/common';
import { StudentsService } from './students.service';
import { CreateStudentDto } from './dto/create-student.dto';
import { UpdateStudentDto } from './dto/update-student.dto';

// 知识点
// 1、restful接口风格

@Controller('students')
export class StudentsController {
  // constructor(private readonly studentsService: StudentsService) { }

  // 第二种用法(自定义名称)
  // constructor(@Inject('mingle') private readonly studentsService: StudentsService) { }
  
  // 第三种自定义注入值
  // constructor(@Inject('mingle') private readonly studentsService: StudentsService,
  //   @Inject('JS') private readonly shopList: string[]) { }

  // 第四种 工厂模式:如果服务 之间有相互的依赖 或者逻辑处理 可以使用 useFactory
  // constructor(@Inject('mingle') private readonly studentsService: StudentsService,
  //   @Inject('JS') private readonly shopList: string[], @Inject('Test') private readonly Test: any) { }
  
   // 第五种 异步模式:useFactory 返回一个promise 或者其他异步操作
   constructor(@Inject('mingle') private readonly studentsService: StudentsService,
     @Inject('JS') private readonly shopList: string[], @Inject('Test') private readonly Test: any,
     @Inject('async') private readonly Async: any
   ) { }

  @Post()
  create(@Body() createStudentDto: CreateStudentDto) {
    return this.studentsService.create(createStudentDto);
  }

  @Get()
  findAll() {
    return this.studentsService.findAll() + this.shopList;
  }

  @Get('async')
  async() {
    return this.Async;
  }

  @Get(':id')
  @Version('1')
  findOne(@Param('id') id: string) {
    return this.studentsService.findOne(+id) + this.Test.StudentsService2;
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateStudentDto: UpdateStudentDto) {
    return this.studentsService.update(+id, updateStudentDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.studentsService.remove(+id);
  }
}
